@extends('admin.index')
@section('content')
    <div class="layuibodycont">
        <div class="clearfix">
            <p class="capitalnav capitalnav02">商品列表</p>
            <div class="orderform">
                <form class="layui-form">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <a class="layui-btn" href="{{ url('adm/order/addgoods') }}" >添加商品</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="streambox">
                <table class="layui-table streamtable" lay-skin="line">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>商品图片</th>
                        <th>商品名称</th>
                        <th>所需环保币</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        @if(!empty($order))
                            @foreach($order as $k=>$v)
                                <tr>
                                    <td><p class="wordpro">{{$v['id']}}</p></td>
                                    <td><p class="wordpro"><img src="{{isset($v['goods_cover'])?$v['goods_cover']:''}}" class="tdcustomerhead"></p></td>
                                    <td><p class="wordpro">{{$v['title']}}</p></td>
                                    <td><p class="wordpro">{{$v['discount_price']}}</p></td>
                                    <td class="text-center">
                                        <button class="layui-btn" onClick='location.href="{{ url('/adm/order/goodsdetail?goods_id='.$v['id']) }}"'>编辑</button>
                                        <button class="layui-btn dels" uid="{{$v['id']}}">删除</button>
                                    </td>

                                </tr>
                            @endforeach
                        @endif
                    </tbody>
                </table>

                <div class="paginationbox">
                    {{ $order->appends(['ktime'=>((isset($times['k']) && !empty($times['k']))?date('Y-m-d H:i:s',$times['k']):''),'gtime'=>((isset($times['e']) && !empty($times['e']))?date('Y-m-d H:i:s',$times['e']):'')])->render() }}
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            //时间选择器
            laydate.render({
                elem: '#LAY_demorange_s'
                ,type: 'datetime'
            });
            laydate.render({
                elem: '#LAY_demorange_e'
                ,type: 'datetime'
            });
        });

        // 导出
        $(document).on('click', '.doexport', function(){
            var channel_account = $('.channel_account').val();
            var order_number = $('.order_number').val();
            var order_status = $('.order_status option:selected').val();
            var ktime = $('input[name=ktime]').val();
            var gtime = $('input[name=gtime]').val();
            location.href = '/merchantadm/order/exportorder?channel_account='+channel_account+'&order_number='+order_number+'&order_status='+order_status+'&ktime='+ktime+'&gtime='+gtime;
        });

        $('.dels').click(function(){
            var uid = $(this).attr('uid');
            if (confirm('确认删除么？') == false){
                return false;
            }else{
                $.ajax({
                    url : '/adm/order/delgood?id='+uid,
                    type : 'get',
                    dateType : 'json',
                    success : function(msg){
                        if (msg.result == 1) {
                            layer.msg('删除成功', {'icon':6});
                            setTimeout(function(){
                                window.location.reload();
                            }, 1000);
                        } else {
                            alert(msg.msg);
                            return false;
                        }
                    },
                    error : function(msg){
                        console.log(msg);
                    }
                })
            }
        });

        // 同意退款
        $(document).on('click', '.agree_ak', function(){
            var order_number = $(this).attr('numb');
            if (!order_number) {
                layer.msg('缺少参数', {icon: 5, time:1000});
                return false;
            }
            layer.open({
                type: 1
                ,title: false //不显示标题栏
                ,closeBtn: false
                ,area: ['400px', '180']
                ,shade: 0.8
                ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
                ,btn: ['确认', '取消']
                ,moveType: 1 //拖拽模式，0或者1
                ,content: $('#layer_maxstock')
                ,success: function(layero){
                },yes: function(index, layero){
                    var remarks = $('input[name=remarks]').val();
                    //var contact = $('input[name=contact]').val();
                    var password = $('input[name=password]').val();
                    if (!remarks) {
                        layer.msg('还未填写备注', {icon: 5});
                        return false;
                    }
                    $.ajax({
                        url : '/merchantadm/order/refunds',
                        type : 'post',
                        data : {order_num:order_number,remarks:remarks,password:password},
                        dataType : 'json',
                        success : function(msg){
                            console.log(msg);
                            if (msg.success == 1) {
                                layer.msg(msg.data, {icon: 6,time:1000});
                                setTimeout(function(){
                                    window.location.reload();
                                }, 1000);
                            } else {
                                layer.msg(msg.error, {icon: 5});
                                return false;
                            }
                        }
                    });
                },btn2:function(index, layero){
                    layer.closeAll();
                }
            });

        });
    </script>
@endsection
{{--弹框的内容--}}
@section('alertbox')
    <div id="layer_maxstock" style="display: none;">
        <div class="goodchatbox">
            <form class="layui-form" id="form_data"  enctype="multipart/form-data">
                <ul class="addlayerul">
                    <li>
                        <div class="addlayerli">
                            <span class="addlayerlipan">备注：</span>
                            <div class="addlayerlidiv">
                                <input type="text" name="remarks" class="addlayerliput" placeholder="" />
                            </div>
                        </div>
                    </li>
                    {{--<li>
                        <div class="addlayerli">
                            <span class="addlayerlipan">联系方式：</span>
                            <div class="addlayerlidiv">
                                <input type="text" name="contact" class="addlayerliput" placeholder="" />
                            </div>
                        </div>
                    </li>--}}
                    <li>
                        <div class="addlayerli">
                            <span class="addlayerlipan">密码：</span>
                            <div class="addlayerlidiv">
                                <input type="password" name="password" class="addlayerliput" placeholder="" />
                            </div>
                        </div>
                    </li>
                </ul>
            </form>
        </div>
    </div>
@endsection